
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>添加管理员-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <link rel="stylesheet" href="../../static/css/font.css" />
    <link rel="stylesheet" href="../../static/css/weadmin.css" />
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="weadmin-body">
    <form class="layui-form" lay-filter="data">
        <div class="layui-form-item">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-block" id="role">

            </div>
        </div>
        <input type="hidden" name="id" id="targetId" value="" />
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>
</div>
<script src="../../static/layui/layui.js" charset="utf-8"></script>
<script>
    layui.extend({
        admin: '{/}../../static/js/admin'
    });
    layui.use('form', function(){
        var $ = layui.jquery ;
        var form = layui.form,formdata=JSON.stringify(parent._formdata);
        var roleStr='',all=parent._formdata["all"],exist=parent._formdata["exist"];
        for (var i = 0; i < all.length; i++) {
            roleStr+='<input type="checkbox" name="'+all[i].id+'" title="'+all[i].roleName+'">';
        }
        $("#role").html(roleStr);
        var data={};
        for (var i = 0; i < exist.length; i++) {
            data[exist[i].id] = true;
        }
        // console.log(data);
        // console.log(form.val("data"));
        form.val("data",data);
        // console.log(JSON.stringify(parent._formdata));
        // console.log(form.val("data"));
        // form.val("data",{"id":1,"account":"admin","password":""});
        //监听提交
        form.on('submit(submit)', function(data){
            // alert(888)
            // console.log(JSON.stringify(data.field));
            var idstr='';
            for (var key in data.field){
                if (data.field[key] == 'on') {
                    idstr += key+",";
                }
            }
            if (idstr.length > 0) {
                idstr=idstr.substr(0,idstr.length-1);
            }
            // console.log(idstr);
            // layer.msg(JSON.stringify(data.field));
            $.ajax({
                type: "post",
                dataType: "json",
                url: "/adminRole/"+parent._formdata['adminId']+"",
                contentType: "application/json;charset=UTF-8",//指定消息请求类型
                data: JSON.stringify({"strIds":idstr}),
                success: function (data) {
                    if(data.code == null || data.code != 200){
                        layer.msg(data.msg);
                    }else{
                        layer.alert("修改成功", {
                            icon: 6
                        },function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //关闭父级页面的表格
                            parent.layui.table.reload('list');
                        });
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>